<?php

$w = 'novelty.status="approved"';
if (array_key_exists('folder', $params)) {
    $w .= ' AND folder.id = "'.DataSource::escape($params['folder']).'"';
} elseif (Request::param('folder')) {
    $w .= ' AND folder.id = "'.DataSource::escape(Request::param('folder')).'"';
}
$news = DataSource::select('cercea, $folder, $novelty.', $w, 'novelty.writed DESC', '5');
$mr = 0;
$mri = 0;
for($i=1; $i < $news->count(); $i++) {
    $nov = $news->item($i);
    if ($nov->novelty->top > $mr) {
        $mr = $nov->novelty->top;
        $mri = $i;
    }
}
for($i=1; $i < $news->count(); $i++) {
    $nov = $news->item($i);
    if ($i != $mri) {
        $nov->novelty->top = 0;
    }
}
$return = $news;
?>
